// 统一封装接口方法
import request from '@/utils/request'
export const reqUerLogin = ({ mobile, code }) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'post',
    data: {
      mobile,
      code
    }
  })
}

// 获得刷新的token,实现无感知刷新
export const getNewToken = () => {
  return request({
    url: '/v1_0/authorizations',
    method: 'put',
    headers: {
      Authorization: `Bearer ${localStorage.getItem('refresh_token')}`
    }
  })
}

export const reqUserChannels = () => {
  return request({
    url: '/v1_0/user/channels',
    method: 'get'
  })
}

export const reqAllChannels = () => {
  return request({
    url: '/v1_0/channels',
    method: 'get'
  })
}
// 更新频道数据
// /v1_0/user/channels
export const reqUpdatedChannel = (channels) => {
  return request({
    url: '/v1_0/user/channels',
    data: {
      channels
    },
    method: 'PUT'
  })
}
export const reqGetArticels = (channel_id, timestamp) => {
  return request(
    {
      url: '/v1_0/articles',
      params: {
        channel_id,
        timestamp
      },
      method: 'get'
    }
  )
}

export const reqDislikeArticle = (articleId) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'post',
    data: {
      target: articleId
    }
  })
}

export const reqReportArticle = ({ target, type, remark }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'post',
    data: {
      target,
      type,
      remark
    }
  })
}

export const reqASSMetu = (keyword) => {
  return request({
    url: '/v1_0/suggestion',
    method: 'get',
    params: {
      q: keyword
    }
  })
}
// 获取搜索结果
// /v1_0/search
// page的默认值为1
export const reqSearchList = ({ kw, page = 1 }) => {
  return request({
    url: '/v1_0/search',
    params: {
      q: kw,
      page
    }
  })
}

// 获得文章的详情
export const reqAticleDetail = ({ id }) => {
  return request({
    url: `/v1_0/articles/${id}`,
    method: 'GET'
  })
}

// 关注作者
export const reqFloowed = ({ atuId }) => {
  return request({
    url: '/v1_0/user/followings',
    method: 'post',
    data: {
      target: atuId
    }
  })
}
// 取消关注
// /v1_0/user/followings/:id
export const reqNoFloowed = ({ atuId }) => {
  return request({
    url: `/v1_0/user/followings/${atuId}`,
    method: 'DELETE'
  })
}
// 点赞
// /v1_0/article/likings
export const reqlike = ({ artId }) => {
  return request({
    url: '/v1_0/article/likings',
    method: 'post',
    data: {
      target: artId
    }
  })
}
// 取消点赞
//  /v1_0/article/likings/:id
export const reqNolike = ({ artId }) => {
  return request({
    url: `/v1_0/article/likings/${artId}`,
    method: 'DELETE'
  })
}
// 获取评论列表
//  /v1_0/comments
export const reqCommentsList = ({ offset = null, id, limit = 10 }) => {
  return request({
    url: '/v1_0/comments',
    method: 'get',
    params: {
      type: 'a',
      source: id,
      limit
    }
  })
}
// 发布评论
export const reqPubCommnet = ({ target, content }) => {
  return request({
    url: '/v1_0/comments',
    method: 'post',
    data: {
      target,
      content
    }
  })
}

// 获取作者的基本的信息
export const reqUserBaseInfo = () => {
  return request({
    url: '/v1_0/user',
    method: 'get'
  })
}

// 获取编辑资料
export const reqUserEdtiInfo = () => {
  return request({
    url: '/v1_0/user/profile',
    method: 'get'
  })
}
// 更新头像,上传图片，因为使用formdata，不需要修改请求头
export const reqUpdatedPhoto = (fd) => {
  return request({
    url: '/v1_0/user/photo',
    data: fd,
    method: 'patch'
  })
}

// 更新资料
export const reqEditUserInfo = ({ birthday = null, uerName = null }) => {
  return request({
    url: '/v1_0/user/profile',
    method: 'patch',
    data: {
      name: uerName,
      birthday
    }
  })
}
